package com.goodving.guli.utility;

import android.content.Context;
import android.content.SharedPreferences;

import com.goodving.guli.model.DailyStats;
import com.goodving.guli.model.UserInfoModel;

import java.util.Calendar;

/**
 * Created by Administrator on 2015/11/17 0017.
 */
public class C1481u {
    public static String TAG  = C1481u.class.getName();
    private static Context mContext = null;
    private static final String f6190c = "android_for_xiaomi";

    public static void setContext(Context context) {
        mContext = context;
    }

    public static Context getContext() {
        return mContext;
    }

    public static long m12076b() {
//        TimeSlot a = TimeSlotsManagerWrapper.m8819a(C1481u.getContext());
//        if (a == null) {
//            C1472m.m12015b(TAG, "timeSlot is NULL!");
//            return LdlDate.m8856a().m8876i().getTime();
//        }
//        long time = a.m8811h().m8876i().getTime();
//        if (time >= C1465g.f6127a) {
//            return time;
//        }
        return C1465g.f6127a;
    }

    public static int m12080c() {
        long j = C1465g.f6127a;
        long b = C1481u.m12076b();
        if (b >= C1465g.f6127a) {
            j = b;
        }
        b = System.currentTimeMillis() - j;
        int ceil = (int) Math.ceil(((double) b) / 8.64E7d);
        if (b <= 0 || ceil == 0) {
            return 1;
        }
        return ceil;
    }

    public static SharedPreferences m12082d() {
        return C1481u.getContext().getSharedPreferences(C1465g.bM, 0);
    }

    public static SharedPreferences m12083e() {
        return C1481u.getContext().getSharedPreferences("XIAOBAI_EV", 0);
    }

    public static SharedPreferences m12084f() {
        return C1481u.getContext().getSharedPreferences(C1465g.bN, 0);
    }

    public static boolean m12074a(String[] strArr) {
        SharedPreferences.Editor edit = C1481u.getContext().getSharedPreferences(C1465g.bM, 0).edit();
        int i = 0;
        while (i < strArr.length) {
            int i2 = i + 1;
            String str = strArr[i];
            i = i2 + 1;
            edit.putString(str, strArr[i2]);
        }
        edit.commit();
        return false;
    }

    public static boolean m12085g() {
        return C1481u.m12082d().getBoolean(C1465g.ai, false);
    }

    public static boolean m12086h() {
        String string = C1481u.m12082d().getString(C1465g.ak, "f");
        if (string.equalsIgnoreCase("m") || string.equals(Constants.VIA_TO_TYPE_QQ_GROUP) || string.equalsIgnoreCase("male")) {
            return true;
        }
        return false;
    }

    public static float m12087i() {
        return C1481u.m12082d().getFloat(C1465g.al, 65.0f);
    }

    public static float m12088j() {
        return C1481u.m12082d().getFloat(C1465g.am, 1.7f);
    }

    public static float m12089k() {
        return ((float) Calendar.getInstance().get(Calendar.YEAR)) - C1481u.m12082d().getFloat(C1465g.an, 1988.0f);
    }

    public static int m12090l() {
        return C1481u.m12082d().getInt(C1465g.f6117Q, 0);
    }

    public static String m12091m() {
        String string = C1481u.m12082d().getString(C1465g.f6115O, "");
        if (C1478r.m12046a(string)) {
            return C1467i.m11962d();
        }
        return string;
    }

    public static boolean m12092n() {
        return C1481u.m12082d().getBoolean(C1465g.bA, false);
    }

    public static boolean m12093o() {
        if (C1481u.m12082d().getLong(C1465g.f6125Y, 0) * 1000 > System.currentTimeMillis()) {
            return true;
        }
        return false;
    }

    public static void m12069a(int i) {
        C1481u.m12077b(i);
        SharedPreferences.Editor edit = C1481u.m12082d().edit();
        edit.putInt(C1465g.f6117Q, i);
        edit.commit();
    }

    public static void m12077b(int i) {
        String c = C1481u.m12081c(i);
        Object obj = null;
//        for (String equals : MiPushClient.getAllAlias(mContext)) {
//            Object obj2;
//            if (equals.equals(c)) {
//                obj2 = 1;
//            } else {
//                MiPushClient.unsetAlias(mContext, c, null);
//                obj2 = obj;
//            }
//            obj = obj2;
//        }
//        if (obj == null) {
//            MiPushClient.setAlias(mContext, C1481u.m12081c(i), null);
//        }
    }

    private static String m12081c(int i) {
        return C1473n.m12019a(f6190c + i);
    }

    public static void m12072a(boolean z) {
//        ServiceLauncher.saveBicycleStatus(z);
        SharedPreferences.Editor edit = C1481u.m12082d().edit();
        edit.putBoolean(C1465g.bA, z);
        edit.commit();
    }

    public static boolean m12094p() {
        if (C1481u.getContext().getSharedPreferences(C1465g.bM, 0).getInt("HEARTBEAT_STYLE", 0) == 1) {
            return true;
        }
        return false;
    }

    public static void m12071a(UserInfoModel userInfoModel) {
        SharedPreferences.Editor edit = C1481u.m12082d().edit();
        edit.putString(C1465g.f6118R, userInfoModel.nickname);
        edit.putString(C1465g.f6119S, userInfoModel.avatar);
        edit.putString(C1465g.ak, userInfoModel.gender);
        edit.putString(C1465g.ae, userInfoModel.email);
        edit.putInt(C1465g.af, userInfoModel.checkin_mcount);
        try {
            edit.putFloat(C1465g.an, Float.valueOf(userInfoModel.birthdate).floatValue());
            edit.putFloat(C1465g.al, Float.valueOf(userInfoModel.weight).floatValue());
            edit.putFloat(C1465g.am, Float.valueOf(userInfoModel.height).floatValue() / 100.0f);
        } catch (Exception e) {
//            C1472m.m12015b(TAG, "user info type is error");
        }
        edit.commit();
    }

//    public static boolean m12073a(float f) {
//        C1228a q = af.m9320q();
//        q.m9274c((double) f);
//        double currentTimeMillis = ((double) System.currentTimeMillis()) / 1000.0d;
//        q.m9260a(currentTimeMillis);
//        q.m9270b(currentTimeMillis);
//        return BodyDBWrapper.m8632a(C1481u.getContext(), q.m9291r());
//    }

    public static UserInfoModel m12095q() {
        SharedPreferences d = C1481u.m12082d();
        UserInfoModel userInfoModel = new UserInfoModel();
        userInfoModel.gender = d.getString(C1465g.ak, "f");
        userInfoModel.weight ="" + d.getFloat(C1465g.al, 70.0f);
        userInfoModel.height ="" + (d.getFloat(C1465g.am, 1.72f) * 100.0f);
        userInfoModel.birthdate ="" + d.getFloat(C1465g.an, 1980.0f);
        userInfoModel.nickname = d.getString(C1465g.f6118R,"");
        userInfoModel.avatar = d.getString(C1465g.f6119S,"");
        userInfoModel.target = d.getInt(C1465g.aq, C1465g.aQ);
        return userInfoModel;
    }

    public static void m12078b(UserInfoModel userInfoModel) {
        SharedPreferences.Editor edit = C1481u.m12082d().edit();
        edit.putBoolean(C1465g.aa, userInfoModel.is_sina);
        edit.putBoolean(C1465g.f6126Z, userInfoModel.is_qq);
        edit.putBoolean(C1465g.ac, userInfoModel.is_email);
        edit.putBoolean(C1465g.ab, userInfoModel.is_wechat);
        edit.commit();
    }

    public static void m12096r() {
        SharedPreferences d = C1481u.m12082d();
        int i = d.getInt(C1465g.aq, C1465g.aQ);
        int i2 = d.getInt(C1465g.ar, 300);
        String string = d.getString(C1465g.ak, "f");
        float f = d.getFloat(C1465g.al, 70.0f);
        float f2 = d.getFloat(C1465g.am, 1.72f);
        float f3 = d.getFloat(C1465g.an, 1980.0f);
        boolean z = true;
        if (string.equals("f")) {
            z = false;
        }
//        ServiceLauncher.saveProfile(z, (int) f3, (int) (f2 * 100.0f), (double) f);
//        ServiceLauncher.saveGoal(i2, i);
    }

    public static int m12097s() {
        return C1481u.m12067a(null);
    }

    public static int m12067a(DailyStats dailyStats) {
        int i = C1481u.m12082d().getInt(C1465g.aq, C1465g.aQ);
        if (dailyStats != null) {
//            return dailyStats.m8681t();
        }
        return i;
    }

    public static int m12098t() {
        return C1481u.m12075b(null);
    }

    public static int m12075b(DailyStats dailyStats) {
        int i = C1481u.m12082d().getInt(C1465g.ar, StatusCode.ST_CODE_SUCCESSED);
        if (dailyStats != null) {
//            return dailyStats.m8680s();
        }
        return i;
    }

    public static double m12064a(double d, double d2) {
        return ((0.25d * d) * d2) * d;
    }

    public static double m12065a(double d, double d2, double d3) {
        if (d / d3 <= 1.68d) {
            return (d * d2) * 0.42d;
        }
        return (((0.25d * d) / d3) * d2) * d;
    }

    public static double m12066a(double d, double d2, double d3, double d4, double d5, boolean z) {
        if (d == 0.0d || d2 == 0.0d) {
            return 0.0d;
        }
        double d6;
        double d7;
        if (d5 <= 16.0d) {
            d6 = 0.9d;
        } else if (d5 > 16.0d && d5 <= 30.0d) {
            d6 = Constants.DEFAULT_INTENSITY;
        } else if (d5 > 30.0d && d5 <= 50.0d) {
            d6 = 0.9d;
        } else if (d5 > 50.0d) {
            d6 = 0.8d;
        } else {
            d6 = Constants.DEFAULT_INTENSITY;
        }
        if (z) {
            d7 = Constants.DEFAULT_INTENSITY;
        } else {
            d7 = 0.9d;
        }
        double d8 = d / d2;
        if (d8 < 1.68d) {
            d8 = (((4.792953E-4d * d4) - 2.65846E-4d) * d3) * d;
        } else {
            d8 = (((((d8 * d8) * d4) - 1.56547328256d) * 2.852948E-4d) * d3) * d2;
        }
        if (d8 < 0.0d) {
            return 0.0d;
        }
        return (d8 * d6) * d7;
    }

    public static boolean m12099u() {
        return !C1478r.m12046a(C1481u.m12082d().getString(C1465g.f6118R,""));
    }

    public static void m12100v() {
        C1481u.m12069a(0);
        SharedPreferences.Editor edit = C1481u.m12082d().edit();
        edit.putString(C1465g.f6118R, null);
        edit.putString(C1465g.f6119S, null);
        edit.putBoolean(C1465g.aa, false);
        edit.putBoolean(C1465g.f6126Z, false);
        edit.putBoolean(C1465g.ac, false);
        edit.putBoolean(C1465g.ad, false);
        edit.putBoolean(C1465g.ab, false);
        edit.putLong(C1465g.f6125Y, 0);
        edit.commit();
    }

    public static void m12079b(boolean z) {
        SharedPreferences.Editor edit = C1481u.m12082d().edit();
        edit.putBoolean("IS_RUNNING", z);
        edit.commit();
    }

    public static boolean m12101w() {
        return C1481u.m12082d().getBoolean("IS_RUNNING", true);
    }

}
